<?php

namespace app\api\controller\user;

use app\api\model\user\UserWelfare;
use app\api\controller\Controller;
use app\common\model\sms\Sms;
use app\common\model\user\Sms as SmsModel;
use app\shop\model\welfare\Welfares;
use think\facade\Db;

class welfare extends Controller
{
    public function add()
    {
        $data = $this->request->post();
        if ( $data['phone'] == '' ) {
            return $this->renderError('手机号不正确');
        }
        if ($data['realname'] == '') {
            return $this->renderError('姓名不能为空');
        }
        if ($data['car_number'] == '') {
            return $this->renderError('车牌号不能为空');
        }
        if ($data['address'] == '') {
            return $this->renderError('地址不能为空');
        }
        $model = new UserWelfare;
        if ($model->add($this->getUser(), $data)) {
            //发送通知短信
            $info = Db::name('supplier')->where(array('welfare_id'=>$data['welfare_id']))->find();
            $model = new SmsModel();
            $model->sendSms($info['link_phone'],$data['phone'],$data['car_number']);
            return $this->renderSuccess('添加成功');
        }
        return $this->renderError('添加失败');
    }
}